<template>
	<a-modal
		v-model:visible="visible"
		title="物品导入明细"
		:mask-closable="false"
		:width="1000"
		:destroy-on-close="true"
		:footer="null"
	>
		<div class="table-operator" style="margin-bottom: 10px">
			<a-form ref="searchFormRef" name="advanced_search" class="ant-advanced-search-form"
					:model="searchFormState">
				<a-row :gutter="24">
					<a-col :span="6">
						<a-form-item label="导入批次">
							<a-tag color="blue">{{impBat}}</a-tag>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="解析结果" name="analFlag">
							<a-select v-model:value="searchFormState.analFlag" placeholder="请选择解析结果" allowClear>
								<a-select-option value="0">未解析</a-select-option>
								<a-select-option value="1">解析失败</a-select-option>
								<a-select-option value="2">解析成功</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :span="4">
						<a-button type="primary" class="primarySele" @click="loadData(searchFormState)"> 查询
						</a-button>
						<a-button class="snowy-buttom-left" @click="resetForm()"> 重置
						</a-button>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<div class="user-table">
			<a-table
				ref="table"
				size="small"
				:columns="commons"
				:data-source="tableData"
				bordered
				:scroll="{ x: 2500 }"
			>
				<template #bodyCell="{ column, record }">
					<template v-if="column.dataIndex === 'analFlag'">
						<a-tag v-if="record.analFlag===0">未解析</a-tag>
						<a-tag color="red" v-if="record.analFlag===1">解析失败</a-tag>
						<a-tag color="green" v-if="record.analFlag===2">解析成功</a-tag>
					</template>
					<template v-if="column.dataIndex === 'operate'">
						<a v-if="record.analFlag!=2" @click="analData(record.id)">解析</a>
					</template>
				</template>
			</a-table>
		</div>
	</a-modal>
</template>
<script setup name="bizGoodsImplItem">
	import { cloneDeep } from "lodash-es";
	import bizGoodsImpApi from '@/api/biz/bizGoodsImpApi'
	import { message } from 'ant-design-vue'

	const visible = ref(false)
	const emit = defineEmits({ successful: null })
	const searchFormState = reactive({})
	const searchFormRef = ref()
	const impBat = ref()
	const impId = ref()
	// 主表格common
	const commons = [
		{
			title: '解析结果',
			dataIndex: 'analFlag',
			fixed: 'left'
		},
		{
			title: '解析说明',
			dataIndex: 'analMsg',
			fixed: 'left'
		},
		{
			title: '物品编号',
			dataIndex: 'goodsCode',
			fixed: 'left'
		},
		{
			title: '物品名称',
			dataIndex: 'goodsName'
		},
		{
			title: 'RFID',
			dataIndex: 'rfidNum'
		},
		{
			title: '是否支持二维码',
			dataIndex: 'qrcodeFlag'
		},
		{
			title: '是否支持条形码',
			dataIndex: 'barcodeFlag'
		},
		{
			title: '资产编号',
			dataIndex: 'assetCode'
		},
		{
			title: '物品型号',
			dataIndex: 'goodsModel'
		},
		{
			title: '物品厂商',
			dataIndex: 'goodsMfr'
		},
		{
			title: '所属组织',
			dataIndex: 'orgName'
		},
		{
			title: '物品分类',
			dataIndex: 'className'
		},
		{
			title: '存放柜子',
			dataIndex: 'bioCabinet'
		},
		{
			title: '柜门',
			dataIndex: 'bioCabinetDoor'
		},
		{
			title: '物品管理员',
			dataIndex: 'adminNames'
		},
		{
			title: '物品标签',
			dataIndex: 'goodsLabels'
		},
		{
			title: '支持扫码借还',
			dataIndex: 'ssbrFlag'
		},
		{
			title: '最长离柜时限（分钟）',
			dataIndex: 'maxLimitLeave'
		},
		{
			title: '到期前提示（分钟）',
			dataIndex: 'impendPrompt'
		},
		{
			title: '连续发送预警时间间隔（分钟）',
			dataIndex: 'alertInterval'
		},
		{
			title: '连续发送预警最大次数',
			dataIndex: 'alertMaxNum'
		},
		{
			title: '物品描述',
			dataIndex: 'goodsDes'
		},
		{
			title: '注意事项',
			dataIndex: 'attention'
		},
		{
			title: '备注',
			dataIndex: 'remarks'
		},
		{
			title: '操作',
			dataIndex: 'operate'
		},
	]
	const tableData = ref([])

	// 打开抽屉
	const onOpen = (record) => {
		visible.value = true
		searchFormState.analFlag = null
		impBat.value = record.impBat
		impId.value = record.id
		loadData()
	}

	const resetForm = () => {
		searchFormRef.value.resetFields()
		searchFormState.analFlag = null
	}

	const loadData = () => {
		const param = cloneDeep(searchFormState)
		param.impId = impId.value
		bizGoodsImpApi.bizGoodsImpItemList(param).then((res) => {
			tableData.value = res
		})
	}

	const analData = (id) => {
		bizGoodsImpApi.analById({
			itemId: id
		}).then((res) => {
			message.success('解析完成！请关注后续解析情况！')
		})
	}

	// 抛出函数
	defineExpose({
		onOpen
	})
</script>

<style lang="less" scoped>
	.user-table {
		overflow: auto;
		max-height: 750px;
	}
</style>
